import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter/cupertino.dart';
class PullToRefresh{

  Widget buildRefresh({@required Function refresh,@required Function load,@required Widget child,@required bool pulldown,@required bool pullup,@required RefreshController refreshController}){
    return  SmartRefresher(
      enablePullDown: pulldown,
      enablePullUp: pullup,
      header: CustomHeader(builder: (BuildContext context,RefreshStatus mode){
        Widget body ;
        if(mode==RefreshStatus.idle){
          body =  Text("");
        }
        else if(mode==RefreshStatus.refreshing){
          body =  CupertinoActivityIndicator();
          // body = RefreshIndicator(child: null, onRefresh: null);
        }
        else if(mode == RefreshStatus.failed){
          body = Text("加载失败");
        }
        else if(mode == RefreshStatus.canRefresh){
          body = Text("释放加载更多");
        }

        else{
          body = Text("");
        }
        return Container(
          height: 55.0,
          child: Center(child:body),
        );
      }),
      footer: CustomFooter(
        builder: (BuildContext context,LoadStatus mode){
          Widget body ;
          if(mode==LoadStatus.idle){
            body =  Text("");
          }
          else if(mode==LoadStatus.loading){
            body =  CupertinoActivityIndicator();
            // body = RefreshIndicator(child: null, onRefresh: null);
          }
          else if(mode == LoadStatus.failed){
            body = Text("");
          }
          else if(mode == LoadStatus.canLoading){
            body = Text("释放加载更多");
          }
          else{
            body = Text("");
          }
          return Container(
            height: 55.0,
            child: Center(child:body),
          );
        },
      ),
      controller: refreshController,
      onRefresh: refresh,
      onLoading: load,
      child: child,
    );
  }


}